package com.atguigu.gmall.product.rpc.controller;


import com.atguigu.gmall.model.product.SkuImage;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.service.SkuImageService;
import com.atguigu.gmall.product.service.SkuInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

@RequestMapping("/api/inner")
@RestController
public class SkuApiController {


    @Autowired
    SkuInfoService skuInfoService;

    @Autowired
    SkuImageService skuImageService;

    /**
     * 获取商品sku的info
     * @param skuId
     * @return
     */
    @GetMapping("/skuinfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable("skuId")Long skuId){

        return skuInfoService.getById(skuId);
    }


    @GetMapping("/skuinfo/images/{skuId}")
    public List<SkuImage> skuImageList(@PathVariable("skuId")Long skuId){

        QueryWrapper<SkuImage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("sku_id",skuId);
        List<SkuImage> images = skuImageService.list(queryWrapper);
        return images;
    }


    /**
     * 查价格
     * @param skuId
     * @return
     */
    @GetMapping("/sku/price/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable("skuId")Long skuId){
        //查询价格
        BigDecimal price = skuInfoService.getSkuPrice(skuId);
        return price;
    }
}
